<?php
	class Comment extends CI_Controller{
		
		public function post(){
			if($this->Model_student->is_logged_in()){

				$this->load->view('comment/post.php');
				if (isset($_POST['submit'])) {
				 $title=$_POST['title'];
				 $content=$_POST['content'];
					if($this->add_new_comment($title,$content)){
				 		redirect("comment/get_all_comment");
					}
				}
			}else{
			redirect("student/login");
			}
		}	

		public function get_all_comment(){
			$this->load->model('Model_comment');
			$all_comment=$this->Model_comment->get_all_comment_info();
			$data['all_comment']=$all_comment;
			$this->load->view('comment/tbody.php',$data);
		}

		public function read(){
			if (isset($_GET['cid'])) {
				$comment_id=$_GET['cid'];
				$resulet_array=$this->show_comment_by_id($comment_id);
				$data['read_detail']=$resulet_array;
				$this->load->view('comment/read.php',$data);
			}else {
				redirect('comment/get_all_comment');
			}
		}

		private function add_new_comment($title,$content){
			$this->load->model('Model_comment');
			return $this->Model_comment->new_comment($title,$content);
		}

		private function show_comment_by_id($comment_id){
			$this->load->model('Model_comment');
			$resulet_array=$this->Model_comment->get_comment_by_id($comment_id);
			return $resulet_array;
			
		}
			
		
	}
?>